using System;
using System.Collections.Generic;

namespace Karma.Framework.Core.Modules.Reports.Definition.Expression
{
    internal class StartsWithExpression : UnaryExpression
    {
        public StartsWithExpression(Criteria criterion)
            : base(criterion)
        {
        }

        public override CompiledExpression Compile(Report report)
        {
            var exp = new CompiledExpression
            {
                Parameters = new Dictionary<string, object>()
            };
            var parameter = GenerateIdentifier();
            exp.Expression = string.Format("{0}.{1} like :{2}", GetIdentifier(report), _operand, parameter);

            exp.Parameters.Add(parameter, _criteria.OperandValues[0] + '%');
            return exp;
        }
    }
}